package com.example.hms.service.servicelmpl;

import com.example.hms.dao.ReserveRecordsDao;
import com.example.hms.entity.ReserveRecords;
import com.example.hms.service.ReserveRecordsService;
import com.example.hms.util.Result;
import com.example.hms.util.ResultSubmit;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
public class ReserveRecordsServiceImpl implements ReserveRecordsService {
    @Resource
    ReserveRecordsDao reserveRecordsDao;

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Override
    public Result selectAllReserveRecords(String roomNumber, String customerName, String identificationCard) {
        List<ReserveRecords> reserveRecordsList  = reserveRecordsDao.selectAllReserveRecords(roomNumber, customerName, identificationCard);
        return ResultSubmit.success(reserveRecordsList);
    }


    @Override
    public int insert(ReserveRecords reserveRecords) {
        reserveRecords.setDataUpdateTime(format.format(new Date()));
        reserveRecords.setReserveRecordsId(Math.abs((int) System.currentTimeMillis()));
        reserveRecords.setDeleteIdentity("未删除");

        int insert1 = reserveRecordsDao.insert(reserveRecords);
        return insert1;
    }
}
